﻿// Decompiled with JetBrains decompiler
// Type: Netick.NetworkPeer
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

#nullable disable
namespace Netick;

public abstract class NetworkPeer : NetworkPlayer
{
  public readonly NetworkTransport Transport;

  public abstract float InKBps { get; }

  public abstract float OutKBps { get; }

  internal NetworkPeer(NetickEngine engine)
    : base(engine)
  {
    this.Transport = engine._transport;
    this.Transport?.InitInternal(this, this.Engine);
  }

  internal virtual void Start(int port)
  {
  }

  internal virtual void Stop()
  {
    this.Transport?.Shutdown();
    if (!this.Engine.IsLoggingEnabled)
      return;
    NetickLogger.Log(this.Engine, (object) "Stopped.");
  }

  internal void TryReceive() => this.Transport?.PollEvents();

  internal abstract void Update();

  public abstract void Receive(
    TransportConnection connection,
    BitBuffer reader,
    TransportDeliveryMethod transportDeliveryMethod = TransportDeliveryMethod.Unreliable);

  public virtual bool OnConnectRequest(byte[] data, int length, IEndPoint source) => false;

  public abstract void OnConnectFailed(ConnectionFailedReason reason);

  public abstract void OnConnected(TransportConnection peer);

  public abstract void OnDisconnected(
    TransportConnection peer,
    TransportDisconnectReason transportDisconnectReason);
}
